package net.pinnoocle.playshoppc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.pinnoocle.playcommon.aop.PassToken;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.group.UpdateGroup;
import net.pinnoocle.playdao.entity.page.PageModel;
import net.pinnoocle.playdao.entity.shopPc.*;
import net.pinnoocle.playservice.service.impl.ScriptServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ye
 * @Description
 * @create 2021-10-20 19:53
 */

@RestController
@RequestMapping("/script")
@Api(tags = "剧本管理")
public class ScriptController {

    @Autowired
    ScriptServiceImpl scriptService;

    @GetMapping("scriptList")
    @ApiOperation("剧本列表")
    public BaseResult<PageModel<ScriptListVo>> scriptList(ScriptListSearchParams params){
        return new BaseResult<PageModel<ScriptListVo>>().ok(scriptService.scriptList(params));
    }

    @PostMapping("saveScript")
    @ApiOperation("添加剧本")
    public BaseResult<String> saveScript(@Validated @RequestBody SaveScriptParams params){
        boolean result = scriptService.saveScript(params);
        if(result){
            return new BaseResult<String>().success("剧本添加成功");
        }
        return new BaseResult<String>().error("剧本添加失败");
    }

    @PostMapping("updateScript")
    @ApiOperation("编辑剧本")
    public BaseResult<String> updateScript(@Validated({UpdateGroup.class}) @RequestBody SaveScriptParams params){
        boolean result = scriptService.updateScript(params);
        if(result){
            return new BaseResult<String>().success("编辑剧本成功");
        }
        return new BaseResult<String>().error("编辑剧本失败");
    }

    @GetMapping("scriptDetail")
    @ApiOperation("剧本详情")
    public BaseResult<ScriptDetailVo> scriptDetail(@RequestParam(name = "scriptId") String scriptId){
        return new BaseResult<ScriptDetailVo>().ok(scriptService.scriptDetail(scriptId));
    }

    @GetMapping("deleteScript")
    @ApiOperation("剧本删除")
    public BaseResult<String> deleteScript(@RequestParam(name = "scriptId") String scriptId){
        boolean result = scriptService.deleteScript(scriptId);
        if(result){
            return new BaseResult<String>().success("编辑删除成功");
        }
        return new BaseResult<String>().error("编辑删除失败");
    }

    @GetMapping("scriptUpAndDown")
    @ApiOperation("剧本上下架 isDisable：0 上架 1 下架")
    public BaseResult<String> scriptUpAndDown(@RequestParam(name = "scriptId") String scriptId,
                                              @RequestParam(name = "isDisable") Integer isDisable){
        boolean result = scriptService.scriptUpAndDown(scriptId,isDisable);
        if(result){
            return new BaseResult<String>().success("剧本"+(isDisable == 0 ? "上架" : "下架")+"成功");
        }
        return new BaseResult<String>().error("剧本"+(isDisable == 0 ? "上架" : "下架")+"失败");
    }

    @GetMapping("scriptLibrary")
    @ApiOperation("剧本库")
    public BaseResult<PageModel<ScriptLibraryListPageVo>> scriptLibrary(ScriptLibraryListSearchParams searchParams){
        return new BaseResult<PageModel<ScriptLibraryListPageVo>>().ok(scriptService.scriptLibrary(searchParams));
    }


    @GetMapping("scriptLibraryDetail")
    @ApiOperation("剧本库剧本详情")
    public BaseResult<ScriptLibraryListPageVo> scriptLibraryDetail(@RequestParam("libraryId") String libraryId){
        return new BaseResult<ScriptLibraryListPageVo>().ok(scriptService.scriptLibraryDetail(libraryId));
    }

    @GetMapping("selectScriptFromLibrary")
    @ApiOperation("从剧本库中拉取剧本")
    public BaseResult<String> selectScriptFromLibrary(@RequestParam(name = "libraryId") String libraryId){
        boolean result = scriptService.selectScriptFromLibrary(libraryId);
        if(result){
            return new BaseResult<String>().success("选择成功");
        }
        return new BaseResult<String>().error("选择失败");
    }
}
